<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Irrlicht 3D Engine: Tutorial 12: Terrain Rendering</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Irrlicht 3D Engine
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('example012.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Tutorial 12: Terrain Rendering </div>  </div>
</div>
<div class="contents">
<div class="textblock"><div class="image">
<img src="012shot.jpg" alt="012shot.jpg"/>
</div>
 <p>This tutorial will briefly show how to use the terrain renderer of Irrlicht. It will also show the terrain renderer triangle selector to be able to do collision detection with terrain.</p>
<p>Note that the Terrain Renderer in Irrlicht is based on Spintz' GeoMipMapSceneNode, lots of thanks go to him. DeusXL provided a new elegant simple solution for building larger area on small heightmaps -&gt; terrain smoothing.</p>
<p>In the beginning there is nothing special. We include the needed header files and create an event listener to listen if the user presses a key: The 'W' key switches to wireframe mode, the 'P' key to pointcloud mode, and the 'D' key toggles between solid and detail mapped material. </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>
<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>

<span class="keyword">using namespace </span>irr;

<span class="preprocessor">#ifdef _MSC_VER</span>
<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
<span class="preprocessor"></span><span class="preprocessor">#endif</span>
<span class="preprocessor"></span>

<span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> <a class="code" href="classirr_1_1_i_event_receiver.html" title="Interface of an object which can receive events.">IEventReceiver</a>
{
<span class="keyword">public</span>:

    MyEventReceiver(<a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* terrain, <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* skybox, <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* skydome) :
        Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true), showDebug(false)
    {
        Skybox-&gt;setVisible(showBox);
        Skydome-&gt;setVisible(!showBox);
    }

    <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> <a class="code" href="structirr_1_1_s_event.html" title="SEvents hold information about an event. See irr::IEventReceiver for details on event handling...">SEvent</a>&amp; event)
    {
        <span class="comment">// check if user presses the key &#39;W&#39; or &#39;D&#39;</span>
        <span class="keywordflow">if</span> (event.<a class="code" href="structirr_1_1_s_event.html#a8b48c016d5c20a9b0967b1ce0fb3ef15">EventType</a> == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; !event.<a class="code" href="structirr_1_1_s_event.html#abe216d2ccbae64f509cca162072c9d7e">KeyInput</a>.PressedDown)
        {
            <span class="keywordflow">switch</span> (event.<a class="code" href="structirr_1_1_s_event.html#abe216d2ccbae64f509cca162072c9d7e">KeyInput</a>.Key)
            {
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae559e3169016a3180c45c2828f391af2">irr::KEY_KEY_W</a>: <span class="comment">// switch wire frame mode</span>
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3abc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>,
                        !Terrain-&gt;getMaterial(0).Wireframe);
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>, <span class="keyword">false</span>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a52e3c10f6d5c2bc0bd446273879f9519">irr::KEY_KEY_P</a>: <span class="comment">// switch wire frame mode</span>
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>,
                        !Terrain-&gt;getMaterial(0).PointCloud);
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3abc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>, <span class="keyword">false</span>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ad20e7e220103e611752b90edeb6cbc9d">irr::KEY_KEY_D</a>: <span class="comment">// toggle detail map</span>
                Terrain-&gt;setMaterialType(
                    Terrain-&gt;getMaterial(0).MaterialType == <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a> ?
                    <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a> : <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae52bafc112fc6c52f6b49cea42fa246e">irr::KEY_KEY_S</a>: <span class="comment">// toggle skies</span>
                showBox=!showBox;
                Skybox-&gt;setVisible(showBox);
                Skydome-&gt;setVisible(!showBox);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ad004cdd263159baf3e4724336aad66d5">irr::KEY_KEY_X</a>: <span class="comment">// toggle debug information</span>
                showDebug=!showDebug;
                Terrain-&gt;setDebugDataVisible(showDebug?<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea80f38e42f1b8cf169e83f44092367bfe" title="EDS_BBOX | EDS_BBOX_BUFFERS.">scene::EDS_BBOX_ALL</a>:<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default )">scene::EDS_OFF</a>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">default</span>:
                <span class="keywordflow">break</span>;
            }
        }

        <span class="keywordflow">return</span> <span class="keyword">false</span>;
    }

<span class="keyword">private</span>:
    <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* Terrain;
    <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* Skybox;
    <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* Skydome;
    <span class="keywordtype">bool</span> showBox;
    <span class="keywordtype">bool</span> showDebug;
};
</pre></div><p>The start of the main function starts like in most other example. We ask the user for the desired renderer and start it up. This time with the advanced parameter handling. </p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
{
    <span class="comment">// ask user for driver</span>
    <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole();
    <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>)
        <span class="keywordflow">return</span> 1;

    <span class="comment">// create device with full flexibility over creation parameters</span>
    <span class="comment">// you can add more parameters if desired, check irr::SIrrlichtCreationParameters</span>
    <a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html" title="Structure for holding Irrlicht Device creation parameters.">irr::SIrrlichtCreationParameters</a> params;
    params.<a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html#a1ea2f50c3b3a8eed6602a1a86e1cdf82" title="Type of video driver used to render graphics.">DriverType</a>=driverType;
    params.<a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html#a1b596e201a6ebd63ca2841d46be10433" title="Size of the window or the video mode in fullscreen mode. Default: 800x600.">WindowSize</a>=core::dimension2d&lt;u32&gt;(640, 480);
    IrrlichtDevice* device = <a class="code" href="namespaceirr.html#ac83a30d674204dcb94d70f849e9b4a62" title="Creates an Irrlicht device with the option to specify advanced parameters.">createDeviceEx</a>(params);

    <span class="keywordflow">if</span> (device == 0)
        <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
</pre></div><p>First, we add standard stuff to the scene: A nice irrlicht engine logo, a small help text, a user controlled camera, and we disable the mouse cursor. </p>
<div class="fragment"><pre class="fragment">    video::IVideoDriver* driver = device-&gt;getVideoDriver();
    scene::ISceneManager* smgr = device-&gt;getSceneManager();
    gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();

    driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>);

    <span class="comment">// add irrlicht logo</span>
    env-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlichtlogo2.png&quot;</span>),
        core::position2d&lt;s32&gt;(10,10));

    <span class="comment">//set other font</span>
    env-&gt;getSkin()-&gt;setFont(env-&gt;getFont(<span class="stringliteral">&quot;../../media/fontlucida.png&quot;</span>));

    <span class="comment">// add some help text</span>
    env-&gt;addStaticText(
        L<span class="stringliteral">&quot;Press &#39;W&#39; to change wireframe mode\nPress &#39;D&#39; to toggle detail map\nPress &#39;S&#39; to toggle skybox/skydome&quot;</span>,
        core::rect&lt;s32&gt;(10,421,250,475), <span class="keyword">true</span>, <span class="keyword">true</span>, 0, -1, <span class="keyword">true</span>);

    <span class="comment">// add camera</span>
    scene::ICameraSceneNode* camera =
        smgr-&gt;addCameraSceneNodeFPS(0,100.0f,1.2f);

    camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(2700*2,255*2,2600*2));
    camera-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(2397*2,343*2,2700*2));
    camera-&gt;setFarValue(42000.0f);

    <span class="comment">// disable mouse cursor</span>
    device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);
</pre></div><p>Here comes the terrain renderer scene node: We add it just like any other scene node to the scene using ISceneManager::addTerrainSceneNode(). The only parameter we use is a file name to the heightmap we use. A heightmap is simply a gray scale texture. The terrain renderer loads it and creates the 3D terrain from it.</p>
<p>To make the terrain look more big, we change the scale factor of it to (40, 4.4, 40). Because we don't have any dynamic lights in the scene, we switch off the lighting, and we set the file terrain-texture.jpg as texture for the terrain and detailmap3.jpg as second texture, called detail map. At last, we set the scale values for the texture: The first texture will be repeated only one time over the whole terrain, and the second one (detail map) 20 times. </p>
<div class="fragment"><pre class="fragment">    <span class="comment">// add terrain scene node</span>
    scene::ITerrainSceneNode* terrain = smgr-&gt;addTerrainSceneNode(
        <span class="stringliteral">&quot;../../media/terrain-heightmap.bmp&quot;</span>,
        0,                  <span class="comment">// parent node</span>
        -1,                 <span class="comment">// node id</span>
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 0.f, 0.f),     <span class="comment">// position</span>
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 0.f, 0.f),     <span class="comment">// rotation</span>
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(40.f, 4.4f, 40.f),  <span class="comment">// scale</span>
        video::SColor ( 255, 255, 255, 255 ),   <span class="comment">// vertexColor</span>
        5,                  <span class="comment">// maxLOD</span>
        <a class="code" href="namespaceirr_1_1scene.html#a6de1eb2d024f82b5b1af499d61523044abe94d6195f435b8e08a38269e63af72e" title="patch size of 17, at most, use 5 levels of detail with this patch size.">scene::ETPS_17</a>,             <span class="comment">// patchSize</span>
        4                   <span class="comment">// smoothFactor</span>
        );

    terrain-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_node.html#a2841d5077854b9981711a403f33762cd" title="Sets all material flags at once to a new value.">setMaterialFlag</a>(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);

    terrain-&gt;setMaterialTexture(0,
            driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/terrain-texture.jpg&quot;</span>));
    terrain-&gt;setMaterialTexture(1,
            driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/detailmap3.jpg&quot;</span>));
    
    terrain-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a>);

    terrain-&gt;scaleTexture(1.0f, 20.0f);
</pre></div><p>To be able to do collision with the terrain, we create a triangle selector. If you want to know what triangle selectors do, just take a look into the collision tutorial. The terrain triangle selector works together with the terrain. To demonstrate this, we create a collision response animator and attach it to the camera, so that the camera will not be able to fly through the terrain. </p>
<div class="fragment"><pre class="fragment">    <span class="comment">// create triangle selector for the terrain </span>
    scene::ITriangleSelector* selector
        = smgr-&gt;createTerrainTriangleSelector(terrain, 0);
    terrain-&gt;setTriangleSelector(selector);

    <span class="comment">// create collision response animator and attach it to the camera</span>
    scene::ISceneNodeAnimator* anim = smgr-&gt;createCollisionResponseAnimator(
        selector, camera, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(60,100,60),
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,50,0));
    selector-&gt;drop();
    camera-&gt;addAnimator(anim);
    anim-&gt;drop();
</pre></div><p> If you need access to the terrain data you can also do this directly via the following code fragment. </p>
<div class="fragment"><pre class="fragment">    scene::CDynamicMeshBuffer* buffer = <span class="keyword">new</span> scene::CDynamicMeshBuffer(<a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">video::EVT_2TCOORDS</a>, <a class="code" href="namespaceirr_1_1video.html#af152a1edea2579f0517e0049525acb55a1c79610ea1191e124887efa16626f299">video::EIT_16BIT</a>);
    terrain-&gt;getMeshBufferForLOD(*buffer, 0);
    video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer-&gt;getVertexBuffer().getData();
    <span class="comment">// Work on data or get the IndexBuffer with a similar call.</span>
    buffer-&gt;drop(); <span class="comment">// When done drop the buffer again.</span>
</pre></div><p>To make the user be able to switch between normal and wireframe mode, we create an instance of the event receiver from above and let Irrlicht know about it. In addition, we add the skybox which we already used in lots of Irrlicht examples and a skydome, which is shown mutually exclusive with the skybox by pressing 'S'. </p>
<div class="fragment"><pre class="fragment">    <span class="comment">// create skybox and skydome</span>
    driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">false</span>);

    scene::ISceneNode* skybox=smgr-&gt;addSkyBoxSceneNode(
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_up.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_dn.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_lf.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_rt.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_ft.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_bk.jpg&quot;</span>));
    scene::ISceneNode* skydome=smgr-&gt;addSkyDomeSceneNode(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/skydome.jpg&quot;</span>),16,8,0.95f,2.0f);

    driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">true</span>);

    <span class="comment">// create event receiver</span>
    MyEventReceiver receiver(terrain, skybox, skydome);
    device-&gt;setEventReceiver(&amp;receiver);
</pre></div><p>That's it, draw everything. </p>
<div class="fragment"><pre class="fragment">    <span class="keywordtype">int</span> lastFPS = -1;

    <span class="keywordflow">while</span>(device-&gt;run())
    <span class="keywordflow">if</span> (device-&gt;isWindowActive())
    {
        driver-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, 0 );

        smgr-&gt;drawAll();
        env-&gt;drawAll();

        driver-&gt;endScene();

        <span class="comment">// display frames per second in window title</span>
        <span class="keywordtype">int</span> fps = driver-&gt;getFPS();
        <span class="keywordflow">if</span> (lastFPS != fps)
        {
            <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Terrain Renderer - Irrlicht Engine [&quot;</span>;
            str += driver-&gt;getName();
            str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
            str += fps;
            <span class="comment">// Also print terrain height of current camera position</span>
            <span class="comment">// We can use camera position because terrain is located at coordinate origin</span>
            str += <span class="stringliteral">&quot; Height: &quot;</span>;
            str += terrain-&gt;getHeight(camera-&gt;getAbsolutePosition().X,
                    camera-&gt;getAbsolutePosition().Z);

            device-&gt;setWindowCaption(str.c_str());
            lastFPS = fps;
        }
    }

    device-&gt;drop();
    
    <span class="keywordflow">return</span> 0;
}
</pre></div><p>Now you know how to use terrain in Irrlicht. </p>
</div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Jan 19 2016 16:08:47 for Irrlicht 3D Engine by
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
